package com.unit6;

import com.unit6.util.GetConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author 李琦 on 2021/8/17.
 * @version java version "16.0.1" 2021-04-20
 *
 */
public class test4 {
    public static void main(String[] args) {
        Connection conn=null;
        Statement stmt=null;
        try{
            conn= GetConnection.getConn();//获取公共的连接对象
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入id:");
            int id=sc.nextInt();
            System.out.println("请输入姓名:");
            String name=sc.next();
            System.out.println("请输入年龄:");
            int age=sc.nextInt();
            System.out.println("请输入性别:");
            String sex=sc.next();
            String sql="insert into stu(id,name,age,sex)" + "values("+id+",'"+name+"',"+age+",'"+sex+"');";
            String sq1="insert into stu(id,name,age,sex)" + "values("+id+",'"+name+"',"+age+",'"+sex+"');";
            //Statement对象用来执行sql语句
            stmt=conn.createStatement();
            //执行sql
            stmt.execute(sql);
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            try {
                stmt.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }
}
